Namespace UI.Web
  ''' <summary>
  ''' TextBox for ASP.NET
  ''' </summary>
  ''' <remarks>Fixes the Maxlength issue.</remarks>
  Public Class TextBox
    Inherits System.Web.UI.WebControls.TextBox

    Protected Overrides Function LoadPostData(ByVal postDataKey As String, ByVal postCollection As Specialized.NameValueCollection) As Boolean

      Page.ClientScript.ValidateEvent(Me.UniqueID, String.Empty)

      Dim oldText As String = Me.Text
      Dim newText As String = postCollection.Item(postDataKey)

      If (newText.Length > Me.MaxLength) Then
        newText = newText.Substring(0, Me.MaxLength)
      End If

      If (Not Me.ReadOnly AndAlso Not oldText.Equals(newText, StringComparison.Ordinal)) Then
        Me.Text = newText
        Return True
      End If

      Return False

    End Function

  End Class
End Namespace

